/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-07 09:26:03
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-03-18 10:51:32
 * @FilePath: /yt-devops/lib/model/user_model.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';
import 'package:native_dart_package/store/sp_store.dart';
import 'package:yt_devops/model/organization_model.dart';
import 'package:yt_devops/model/role_model.dart';

part 'user_model.g.dart';

@JsonSerializable()
class UserModel {
  String? loginedAccount; //当前登陆时用的账号

  /// 用户ID
  int? userId;

  /// 角色ID
  int? orgId;
  String? userName;
  String? nickName;
  String? email;
  String? phone;
  Sex? sex;
  String? avatar;
  String? password;

  /// 角色状态
  String? status;

  int? orgType;
  //deviceToken 推送用
  String? deviceToken;

  /// 组织
  OrgnizationModel? org;

  /// 角色类型
  List<RoleModel>? roles;

  /// 国际化语言
  String? lang;

  /// 权限
  List<String>? appPermissions;

  /// web权限
  List<String>? permissions;

  UserModel({
    this.userId,
    this.loginedAccount,
    this.orgId,
    this.userName,
    this.nickName,
    this.email,
    this.phone,
    this.sex,
    this.avatar,
    this.password,
    this.deviceToken,
    this.status,
    this.roles,
    this.org,
    this.orgType,
    this.lang,
    this.appPermissions,
    this.permissions,
  });

  factory UserModel.fromJson(Map<String, dynamic> json) =>
      _$UserModelFromJson(json);

  Map<String, dynamic> toJson() => _$UserModelToJson(this);
}

@JsonEnum(valueField: "value")
enum Sex {
  men('0'),
  women('1');

  final String value;
  const Sex(this.value);

  String get label {
    if (value == '0') {
      return '男';
    } else {
      return '女';
    }
  }
}

@JsonEnum(valueField: "value")
enum OrganizationType {
  admin(1), //1 系统管理员
  installProvider(3), // 3 安装商
  owner(4), //4 业主
  operator(5), //5 运营商
  productManage(6), //6 产品管理员
  other(-1); // 其他角色

  final int? value;
  const OrganizationType(this.value);

  static OrganizationType getType(int number) =>
      OrganizationType.values.firstWhere((activity) => activity.value == number,
          orElse: () => OrganizationType.other);
}
